/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package editor.impl;

import editor.Attribute;
import editor.DefaultTypes;
import editor.EditorPackage;
import editor.Element;
import editor.RootRelationship;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Element</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link editor.impl.ElementImpl#getElementType <em>Element Type</em>}</li>
 *   <li>{@link editor.impl.ElementImpl#getIncomingComplexElement <em>Incoming Complex Element</em>}</li>
 *   <li>{@link editor.impl.ElementImpl#getAttributes <em>Attributes</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ElementImpl extends NodeImpl implements Element {
	/**
   * The default value of the '{@link #getElementType() <em>Element Type</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getElementType()
   * @generated
   * @ordered
   */
	protected static final DefaultTypes ELEMENT_TYPE_EDEFAULT = DefaultTypes.NONE;

	/**
   * The cached value of the '{@link #getElementType() <em>Element Type</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getElementType()
   * @generated
   * @ordered
   */
	protected DefaultTypes elementType = ELEMENT_TYPE_EDEFAULT;

	/**
   * The cached value of the '{@link #getIncomingComplexElement() <em>Incoming Complex Element</em>}' reference.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getIncomingComplexElement()
   * @generated
   * @ordered
   */
	protected RootRelationship incomingComplexElement;

	/**
   * The cached value of the '{@link #getAttributes() <em>Attributes</em>}' containment reference list.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getAttributes()
   * @generated
   * @ordered
   */
	protected EList<Attribute> attributes;

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	protected ElementImpl() {
    super();
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	protected EClass eStaticClass() {
    return EditorPackage.Literals.ELEMENT;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public DefaultTypes getElementType() {
    return elementType;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setElementType(DefaultTypes newElementType) {
    DefaultTypes oldElementType = elementType;
    elementType = newElementType == null ? ELEMENT_TYPE_EDEFAULT : newElementType;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EditorPackage.ELEMENT__ELEMENT_TYPE, oldElementType, elementType));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public RootRelationship getIncomingComplexElement() {
    if (incomingComplexElement != null && incomingComplexElement.eIsProxy())
    {
      InternalEObject oldIncomingComplexElement = (InternalEObject)incomingComplexElement;
      incomingComplexElement = (RootRelationship)eResolveProxy(oldIncomingComplexElement);
      if (incomingComplexElement != oldIncomingComplexElement)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, EditorPackage.ELEMENT__INCOMING_COMPLEX_ELEMENT, oldIncomingComplexElement, incomingComplexElement));
      }
    }
    return incomingComplexElement;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public RootRelationship basicGetIncomingComplexElement() {
    return incomingComplexElement;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetIncomingComplexElement(RootRelationship newIncomingComplexElement, NotificationChain msgs) {
    RootRelationship oldIncomingComplexElement = incomingComplexElement;
    incomingComplexElement = newIncomingComplexElement;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EditorPackage.ELEMENT__INCOMING_COMPLEX_ELEMENT, oldIncomingComplexElement, newIncomingComplexElement);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setIncomingComplexElement(RootRelationship newIncomingComplexElement) {
    if (newIncomingComplexElement != incomingComplexElement)
    {
      NotificationChain msgs = null;
      if (incomingComplexElement != null)
        msgs = ((InternalEObject)incomingComplexElement).eInverseRemove(this, EditorPackage.ROOT_RELATIONSHIP__TARGET_ROOT, RootRelationship.class, msgs);
      if (newIncomingComplexElement != null)
        msgs = ((InternalEObject)newIncomingComplexElement).eInverseAdd(this, EditorPackage.ROOT_RELATIONSHIP__TARGET_ROOT, RootRelationship.class, msgs);
      msgs = basicSetIncomingComplexElement(newIncomingComplexElement, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EditorPackage.ELEMENT__INCOMING_COMPLEX_ELEMENT, newIncomingComplexElement, newIncomingComplexElement));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public EList<Attribute> getAttributes() {
    if (attributes == null)
    {
      attributes = new EObjectContainmentEList<Attribute>(Attribute.class, this, EditorPackage.ELEMENT__ATTRIBUTES);
    }
    return attributes;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case EditorPackage.ELEMENT__INCOMING_COMPLEX_ELEMENT:
        if (incomingComplexElement != null)
          msgs = ((InternalEObject)incomingComplexElement).eInverseRemove(this, EditorPackage.ROOT_RELATIONSHIP__TARGET_ROOT, RootRelationship.class, msgs);
        return basicSetIncomingComplexElement((RootRelationship)otherEnd, msgs);
    }
    return super.eInverseAdd(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case EditorPackage.ELEMENT__INCOMING_COMPLEX_ELEMENT:
        return basicSetIncomingComplexElement(null, msgs);
      case EditorPackage.ELEMENT__ATTRIBUTES:
        return ((InternalEList<?>)getAttributes()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
    switch (featureID)
    {
      case EditorPackage.ELEMENT__ELEMENT_TYPE:
        return getElementType();
      case EditorPackage.ELEMENT__INCOMING_COMPLEX_ELEMENT:
        if (resolve) return getIncomingComplexElement();
        return basicGetIncomingComplexElement();
      case EditorPackage.ELEMENT__ATTRIBUTES:
        return getAttributes();
    }
    return super.eGet(featureID, resolve, coreType);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
    switch (featureID)
    {
      case EditorPackage.ELEMENT__ELEMENT_TYPE:
        setElementType((DefaultTypes)newValue);
        return;
      case EditorPackage.ELEMENT__INCOMING_COMPLEX_ELEMENT:
        setIncomingComplexElement((RootRelationship)newValue);
        return;
      case EditorPackage.ELEMENT__ATTRIBUTES:
        getAttributes().clear();
        getAttributes().addAll((Collection<? extends Attribute>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eUnset(int featureID) {
    switch (featureID)
    {
      case EditorPackage.ELEMENT__ELEMENT_TYPE:
        setElementType(ELEMENT_TYPE_EDEFAULT);
        return;
      case EditorPackage.ELEMENT__INCOMING_COMPLEX_ELEMENT:
        setIncomingComplexElement((RootRelationship)null);
        return;
      case EditorPackage.ELEMENT__ATTRIBUTES:
        getAttributes().clear();
        return;
    }
    super.eUnset(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public boolean eIsSet(int featureID) {
    switch (featureID)
    {
      case EditorPackage.ELEMENT__ELEMENT_TYPE:
        return elementType != ELEMENT_TYPE_EDEFAULT;
      case EditorPackage.ELEMENT__INCOMING_COMPLEX_ELEMENT:
        return incomingComplexElement != null;
      case EditorPackage.ELEMENT__ATTRIBUTES:
        return attributes != null && !attributes.isEmpty();
    }
    return super.eIsSet(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public String toString() {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (elementType: ");
    result.append(elementType);
    result.append(')');
    return result.toString();
  }

} //ElementImpl
